package role

import (
	"net/http"
	"strconv"

	"go-zero-mall/app/admin/cmd/api/internal/logic/role"
	"go-zero-mall/app/admin/cmd/api/internal/svc"
	"go-zero-mall/app/admin/cmd/api/internal/types"
	"go-zero-mall/common/result"
)

func RolePageListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		pageSize, err := strconv.ParseInt(r.URL.Query().Get("pageSize"), 10, 64)
		if err != nil {
			result.ParamErrorResult(r, w, err)
			return
		}
		pageNum, err := strconv.ParseInt(r.URL.Query().Get("pageNum"), 10, 64)
		if err != nil {
			result.ParamErrorResult(r, w, err)
			return
		}
		req := types.RolePageReq{
			PageSize: pageSize,
			PageNum:  pageNum,
			Keyword:  r.URL.Query().Get("keyword"),
		}

		l := role.NewRolePageListLogic(r.Context(), svcCtx)
		resp, err := l.RolePageList(&req)
		result.HttpResult(r, w, resp, err)
	}
}
